From e483e49b246daa6ac2ffab191189f14e4cb0fdf1 Mon Sep 17 00:00:00 2001 From: robertlipe Date: Sun, 8 Jun 2014 23:39:54 +0000 Subject: [PATCH] More NEW_STRINGS-style cleanups. --- gpsbabel/kml.cc | 5 +---- gpsbabel/lowranceusr.cc | 26 ++++++++++--------------- gpsbabel/mmo.cc | 43 ++++++++++++++++------------------------- 3 files changed, 28 insertions(+), 46 deletions(-) diff --git a/gpsbabel/kml.cc b/gpsbabel/kml.cc index c331040d5..9c661749c 100644 --- a/gpsbabel/kml.cc +++ b/gpsbabel/kml.cc @@ -1316,14 +1316,11 @@ QString kml_geocache_get_logs(const Waypoint* wpt) if (logpart) { gpsbabel::DateTime t = xml_parse_time(logpart->cdata); if (t.isValid()) { - char* temp; - xasprintf(&temp, + r += QString().sprintf( " %04d-%02d-%02d", t.date().year(), t.date().month(), t.date().day()); - r += temp; - xfree(temp); } } diff --git a/gpsbabel/lowranceusr.cc b/gpsbabel/lowranceusr.cc index 2830abebe..edea6a4bd 100644 --- a/gpsbabel/lowranceusr.cc +++ b/gpsbabel/lowranceusr.cc @@ -679,7 +679,6 @@ lowranceusr_waypt_disp(const Waypoint* wpt) { int text_len, Lat, Lon, Time, SymbolId; short int WayptType; - char* comment; int alt = METERS_TO_FEET(wpt->altitude); if (wpt->altitude == unknown_alt) { @@ -739,14 +738,13 @@ lowranceusr_waypt_disp(const Waypoint* wpt) * Comments are now used by the iFinder (Expedition C supports them) */ if (wpt->description != wpt->shortname) { - comment = xstrdup(wpt->description); - text_len = strlen(comment); + QString comment = xstrdup(wpt->description); + text_len = comment.length(); if (text_len > MAXUSRSTRINGSIZE) { text_len = MAXUSRSTRINGSIZE; } gbfputint32(text_len, file_out); - gbfwrite(comment, 1, text_len, file_out); - xfree(comment); + gbfwrite(CSTR(comment), 1, text_len, file_out); } else { text_len = 0; gbfputint32(text_len, file_out); @@ -842,23 +840,21 @@ static void lowranceusr_track_hdr(const route_head* trk) { int text_len; - char* name, tmp_name[20]; + QString name; short num_trail_points, max_trail_size; char visible=1; ++trail_count; //TODO: This whole function needs to be replaced... if (!trk->rte_name.isEmpty()) { - name = xstrdup(trk->rte_name); + name = trk->rte_name; } else if (!trk->rte_desc.isEmpty()) { - name = xstrdup(trk->rte_desc); + name = trk->rte_desc; } else { - tmp_name[0]='\0'; - snprintf(tmp_name, sizeof(tmp_name), "Babel %d", trail_count); - name = xstrdup(tmp_name); + name = name + QString("Babel %1").arg(trail_count); } - text_len = strlen(name); + text_len = name.length(); if (text_len > MAXUSRSTRINGSIZE) { text_len = MAXUSRSTRINGSIZE; } @@ -868,10 +864,9 @@ lowranceusr_track_hdr(const route_head* trk) gbfputint32(text_len, file_out); if (global_opts.debug_level >= 1) { - printf(MYNAME " track_hdr: trail name = %s\n", name); + qDebug() << MYNAME << " track_hdr: trail name" << name; } - - gbfwrite(name, 1, text_len, file_out); + gbfwrite(CSTR(name), 1, text_len, file_out); num_trail_points = (short) trk->rte_waypt_ct; max_trail_size = MAX_TRAIL_POINTS; @@ -888,7 +883,6 @@ lowranceusr_track_hdr(const route_head* trk) gbfputint16(num_trail_points, file_out); gbfputint16(max_trail_size, file_out); gbfputint16(num_section_points, file_out); - xfree(name); trail_point_count=1; } diff --git a/gpsbabel/mmo.cc b/gpsbabel/mmo.cc index 6e18f672a..f57ccf3e7 100644 --- a/gpsbabel/mmo.cc +++ b/gpsbabel/mmo.cc @@ -968,10 +968,12 @@ mmo_finalize_rtept_cb(const Waypoint* wptref) if ((wpt->shortname[0] == 1) && (wpt->latitude == 0) && (wpt->longitude == 0)) { mmo_data_t* data; Waypoint* wpt2; -#if NEW_STRINGS -#warning this code is on drugs. + +// This code path isn't tested in anything we have and I have No Idea +// what it was trying to do. Throw a hard error to force the hand of +// getting a sample file. abort(); -#else +#if OLD sscanf(wpt->shortname + 1, "%p", &data); #endif wpt2 = (Waypoint*)data->data; @@ -1143,6 +1145,12 @@ mmo_writestr(const char* str) } } +static void +mmo_writestr(const QString& str) { + // If UTF-8 is used instgead of Latin1, we fail in weird ways. + mmo_writestr(str.toLatin1().constData()); +} + static void mmo_enum_waypt_cb(const Waypoint* wpt) @@ -1230,7 +1238,7 @@ mmo_write_obj_head(const char* sobj, const char* name, const time_t ctime, static void mmo_write_wpt_cb(const Waypoint* wpt) { - char* str; + QString str; QString cx; int objid; time_t time; @@ -1257,13 +1265,8 @@ mmo_write_wpt_cb(const Waypoint* wpt) } DBG(("write", "waypoint \"%s\"\n", wpt->shortname ? wpt->shortname : "Mark")); -#if NEW_STRINGS objid = mmo_write_obj_head("CObjWaypoint", wpt->shortname.isEmpty() ? "Mark" : CSTRc(wpt->shortname), time, obj_type_wpt); -#else - objid = mmo_write_obj_head("CObjWaypoint", - (wpt->shortname && *wpt->shortname) ? CSTRc(wpt->shortname) : "Mark", time, obj_type_wpt); -#endif data = mmo_register_object(objid, wpt, wptdata); data->refct = 1; mmo_write_category("CCategory", (mmo_datatype == rtedata) ? "Waypoints" : "Marks"); @@ -1280,12 +1283,10 @@ mmo_write_wpt_cb(const Waypoint* wpt) } if (wpt->HasUrlLink()) { - str = xstrdup("_FILE_ "); + str = "_FILE_ "; UrlLink l = wpt->GetUrlLink(); - str = xstrappend(str, l.url_.toUtf8().data()); - str = xstrappend(str, "\n"); - } else { - str = xstrdup(""); + str += l.url_; + str += "\n"; } cx = wpt->notes; @@ -1302,13 +1303,12 @@ mmo_write_wpt_cb(const Waypoint* wpt) tmp.is_html = 1; cx = kml = strip_html(&tmp); } - str = xstrappend(str, CSTRc(cx)); + str += cx; if (kml) { xfree(kml); } } mmo_writestr(str); - xfree(str); gbfputuint32(0x01, fout); if WAYPT_HAS(wpt, proximity) { @@ -1358,13 +1358,8 @@ mmo_write_rte_head_cb(const route_head* rte) if (time == 0x7FFFFFFF) { time = gpsbabel_time; } -#if NEW_STRINGS objid = mmo_write_obj_head("CObjRoute", rte->rte_name.isEmpty() ? "Route" : CSTRc(rte->rte_name), time, obj_type_rte); -#else - objid = mmo_write_obj_head("CObjRoute", - (rte->rte_name && *rte->rte_name) ? CSTRc(rte->rte_name) : "Route", time, obj_type_rte); -#endif mmo_register_object(objid, rte, rtedata); mmo_write_category("CCategory", "Route"); gbfputc(0, fout); /* unknown */ @@ -1413,13 +1408,9 @@ mmo_write_trk_head_cb(const route_head* trk) if (trk->rte_waypt_ct <= 0) { return; } -#if NEW_STRINGS objid = mmo_write_obj_head("CObjTrack", trk->rte_name.isEmpty() ? "Track" : CSTRc(trk->rte_name), gpsbabel_time, obj_type_trk); -#else - objid = mmo_write_obj_head("CObjTrack", - (trk->rte_name && *trk->rte_name) ? CSTRc(trk->rte_name) : "Track", gpsbabel_time, obj_type_trk); -#endif + mmo_write_category("CCategory", "Track"); gbfputuint16(trk->rte_waypt_ct, fout); -- 2.30.2